home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-05-18 | 4.8 KB | 213 lines | [TEXT/PJMM] |
- (*}
- { Zoom-Rect-er}
- { DTS Code Snippet}
- { }
- { 1/6/92 Steve Falkenburg}
- { }
- { This snippet shows how to do "Finder" style zooming between two rectangles.}
- { The boolean flag "kZoomLarger" controls the proportional direction of the zooming.}
- { }
- { To get the two rectangles, you drag them out rubberbanded, and the zoom occurs between}
- { them. To quit, click the close box.}
- { }
- { If you want to do zooms between windows, open up a port with the dimensions of the desktop}
- { (from GetGrayRgn()).}
- { }
- { DON'T use this as a sample of how to do rubberband drawing!!! It's sort of hacked}
- { together bypassing the event mechanism and just using Button().}
- {*)
-
- program ZoomRecter;
-
- const
- kNumSteps = 14;
- kRectsVisible = 4;
- kZoomRatio = 0.7;
- kDelayTicks = 1;
-
- kZoomLarger = true;{ change this to zoom "inward"}
-
- var
- gDone: Boolean;
-
-
- procedure InitStuff;
- begin
- {$IFC UNDEFINED THINK_PASCAL}
- InitGraf(@qd.thePort);
- {$ELSEC}
- InitGraf(@thePort);
- {$ENDC}
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- InitCursor;
- FlushEvents(everyEvent, 0);
- end; {InitStuff}
-
-
- procedure ZoomRect (zoomLarger: Boolean; var smallRect: Rect; var bigRect: Rect);
- var
- firstStep, stepValue, trailer, zoomRatio: double;
- i, step: Integer;
- curRect: Rect;
- ticks: LongInt;
- procedure CalcRect (var theRect: Rect; var smallRect: Rect; var bigRect: Rect; stepValue: double);
- begin
- theRect.left := smallRect.left + Trunc((bigRect.left - smallRect.left) * stepValue);
- theRect.top := smallRect.top + Trunc((bigRect.top - smallRect.top) * stepValue);
- theRect.right := smallRect.right + Trunc((bigRect.right - smallRect.right) * stepValue);
- theRect.bottom := smallRect.bottom + Trunc((bigRect.bottom - smallRect.bottom) * stepValue);
- end; {CalcRect}
- begin
- {$IFC UNDEFINED THINK_PASCAL}
- PenPat(qd.gray);
- {$ELSEC}
- PenPat(gray);
- {$ENDC}
- PenMode(patXor);
-
- firstStep := kZoomRatio;
- for i := 0 to kNumSteps - 1 do
- begin
- firstStep := firstStep * kZoomRatio;
- end;
-
- if not zoomLarger then
- begin
- zoomRatio := 1.0 / kZoomRatio;
- firstStep := 1.0 - firstStep;
- end
- else
- zoomRatio := kZoomRatio;
-
- trailer := firstStep;
- stepValue := firstStep;
- for step := 0 to kNumSteps + kRectsVisible - 1 do
- { draw new frame}
- begin
- if step < kNumSteps then
- begin
- stepValue := stepValue / zoomRatio;
- CalcRect(curRect, smallRect, bigRect, stepValue);
- FrameRect(curRect);
- end;
-
- { erase old frame}
-
- if (step >= kRectsVisible) then
- begin
- trailer := trailer / zoomRatio;
- CalcRect(curRect, smallRect, bigRect, trailer);
- FrameRect(curRect);
- end;
-
- Delay(kDelayTicks, ticks);
- end;
-
- PenNormal;
- end; {ZoomRect}
-
-
- function GetRects (var zoomFrom: Rect; var zoomTo: Rect): Boolean;
- var
- numRects: Integer;
- ev: EventRecord;
- theRect, drawRect: Rect;
- firstPt, curPt, oldPt, globalPt: Point;
- theKeys: KeyMap;
- window: WindowPtr;
- procedure FixRect (var theRect: Rect; var rightRect: Rect);
- begin
- if (theRect.right > theRect.left) then
- begin
- rightRect.right := theRect.right;
- rightRect.left := theRect.left;
- end
- else
- begin
- rightRect.right := theRect.left;
- rightRect.left := theRect.right;
- end;
-
- if (theRect.bottom > theRect.top) then
- begin
- rightRect.bottom := theRect.bottom;
- rightRect.top := theRect.top;
- end
- else
- begin
- rightRect.bottom := theRect.top;
- rightRect.top := theRect.bottom;
- end;
- end; {FixRect}
- begin
- numRects := 0;
- PenMode(patXor);
-
- repeat
- while not Button do
- ;
-
- GetMouse(globalPt);
- LocalToGlobal(globalPt);
- if (FindWindow(globalPt, window) = inGoAway) and (window = FrontWindow) then
- begin
- gDone := true;
- GetRects := false;
- end;
-
- GetMouse(firstPt);
- oldPt := firstPt;
- SetRect(theRect, firstPt.h, firstPt.v, firstPt.h, firstPt.v);
- while Button do
- begin
- GetMouse(curPt);
- if (not EqualPt(curPt, oldPt)) then
- begin
- FixRect(theRect, drawRect);
- FrameRect(drawRect);
- oldPt := curPt;
- theRect.right := curPt.h;
- theRect.bottom := curPt.v;
- FixRect(theRect, drawRect);
- FrameRect(drawRect);
- end;
- end;
-
- FixRect(theRect, drawRect);
- if numRects = 0 then
- zoomFrom := drawRect
- else
- zoomTo := drawRect;
-
- numRects := numRects + 1;
-
- until not (numRects < 2);
-
- PenNormal;
- end; {GetRects}
-
- {main}
- var
- window: WindowPtr;
- bounds, zoomFrom, zoomTo: Rect;
-
- begin
- InitStuff;
- bounds := screenBits.bounds;
- bounds.top := 40;
- InsetRect(bounds, 20, 20);
- {SetRect(bounds, 12, 44, 500, 330);}
- window := NewWindow(nil, bounds, 'Drag Two Rects to Zoom', true, documentProc, WindowPtr(-1), true, 0);
- SetPort(window);
-
- repeat
- if GetRects(zoomFrom, zoomTo) then
- ZoomRect(kZoomLarger, zoomFrom, zoomTo);
- EraseRect(window^.portRect);
- until gDone;
- FlushEvents(everyEvent, 0);
- end.